package com.yamaikeji.quartz.task;

import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
import com.yamaikeji.common.utils.StringUtils;
import com.yamaikeji.system.domain.plan.Task;
import com.yamaikeji.system.domain.plan.User;
import com.yamaikeji.system.service.plan.ITaskService;
import com.yamaikeji.system.service.plan.IUserService;
import com.yamaikeji.system.util.PushUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author yamaikeji
 */
@Component("pushItemTask")
public class PushItemTask {

    @Autowired
    private IUserService pUserService;

    @Autowired
    private ITaskService pTaskService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        User getUser = new User();
        List<User> userList = pUserService.selectUserList(getUser);
        for (User user : userList) {
            if ("1".equals(user.getSetTipFlag())) {
                Task getTask = new Task();
                getTask.setUserNo(user.getUserNo());
                getTask.setNowTime(LocalDate.now());
                getTask.setTaskStatus("0");
                List<Task> taskList = pTaskService.selectTaskList(getTask);
                SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                String nowTime = sdf.format(new Date());
                if (CollectionUtils.isNotEmpty(taskList)) {
                    for (Task task : taskList) {
                        if ("1".equals(task.getTipSwitch())) {
                            if (nowTime.equals(task.getTipTime())) {
                                Alert alert = new Alert();
                                alert.setTitle("叮咚待办");
                                alert.setBody("待办提醒：" + task.getPlanName());
                                PushUtil.pushMsg(user.getUserNo(), alert);
                            }
                        }
                    }
                }
            }
        }
        System.out.println("执行无参方法");
    }
}
